import json
from pyecharts.charts import Map
from pyecharts.options import *
f = open("E:/疫情.txt", "r", encoding="UTF-8")
data = f.read()
data = json.loads(data)
data_province_list = data["areaTree"][0]["children"]
data_list = []
for province_data in data_province_list:
    province_name = province_data["name"]
    province_name = province_name + "省"
    province_confirm = province_data["total"]["confirm"]  # 省份确诊人数
    data_list.append((province_name, province_confirm))  # 得到列表嵌套元组， 元组为省份名+已确诊人数
print(data_list)
map1 = Map()
map1.add("全国疫情数据", data_list, "china")
map1.set_global_opts(
    title_opts=TitleOpts(pos_left="center", pos_bottom="1%", title="全国疫情数据"),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
                {"min": 1, "max": 9, "label": "1-9人", "color": "#3CA9C4"},
                {"min": 10, "max": 99, "label": "10-99人", "color": "#D5B32B"},
                {"min": 100, "max": 999, "label": "100-9999人", "color": "#E6941A"},
                {"min": 1000, "max": 9999, "label": "1000-9999人", "color": "#CC5233"},
                {"min": 10000, "label": "10000以上", "color": "#FF0000"},
        ]
    ),
    toolbox_opts=ToolboxOpts(is_show=True),
)
map1.render()
